package avicit.bdp.dcs.precheck.rest;

import avicit.bdp.dcs.job.dto.JobDTO;
import avicit.bdp.dcs.precheck.dto.PrecheckProgressDto;
import avicit.bdp.dcs.precheck.service.PrecheckService;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2020-08-05 14:30
 * @类说明：预检查相关接口
 * @修改记录：
 */
@RestController
@RequestMapping("/api/bdp/dcs/precheck/PrecheckRest")
@Api(tags = "预检查相关接口")
public class PrecheckRest {

    private static final Logger logger = LoggerFactory.getLogger(PrecheckRest.class);

    @Autowired
    private PrecheckService precheckService;

    @PostMapping("/saveJobPrecheck")
    @ApiOperation(value = "保存Job预检查关联数据")
    public ResponseMsg<String> saveJobPrecheck(@ApiParam(value = "jobId", name = "jobId") @RequestParam String jobId) throws Exception{
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(precheckService.saveJobPrecheck(jobId));
        return responseMsg;
    }

    @PostMapping("/updateJobPrecheck")
    @ApiOperation(value = "更新Job预检查关联数据")
    public ResponseMsg<String> updateJobPrecheck(@ApiParam(value = "jobId", name = "jobId") @RequestParam String jobId) throws Exception{
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(precheckService.updateJobPrecheck(jobId));
        return responseMsg;
    }

    @GetMapping("/getPrecheckListAndProgress")
    @ApiOperation(value = "查询预检查信息和进度信息")
    public ResponseMsg<PrecheckProgressDto> getPrecheckListAndProgress(@ApiParam(value = "jobId", name = "jobId", required = true) @RequestParam String jobId) throws Exception{
        ResponseMsg<PrecheckProgressDto> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(precheckService.getPrecheckListAndProgress(jobId));
        return responseMsg;
    }

    @PostMapping("/executePrecheck")
    @ApiOperation(value = "执行预检查")
    public ResponseMsg executePrecheck(@ApiParam(value = "jobId", name = "jobId", required = true) @RequestBody JobDTO jobDTO) throws Exception{
        ResponseMsg responseMsg = new ResponseMsg<>();
        precheckService.executePrecheck(jobDTO.getId());
        return responseMsg;
    }

}
